<?php
class SaveReplay extends Action {
	/* (non-PHPdoc)
	 * @see Action::execute()
	 */
	public function execute($params) {
		
		$me = check_login ( ADMIN_LOGIN_PAGE );
		
		$data ['success'] = false;
		
		$reply ['anw_content'] = rqst ( 'anwer_content' );
		
		$ask_id = irqst ( 'ask_id' );
		
		if (empty ( $reply ['anw_content'] )) {
			$data ['msg'] = '回复不能为空.';
		} else if (empty ( $ask_id )) {
			$data ['msg'] = '未指定要回复的留言.';
		} else {
			$reply ['anwer_time'] = time ();
			$reply ['anwer_name'] = $me->name;
			$reply ['status'] = 'pass';
			$askM = new PlugAskModel ();
			$rst = $askM->update ( $reply, $ask_id );
			if ($rst) {
				$data ['success'] = true;
			} else {
				$data ['msg'] = '回复留言失败:' . $askM->last_error_msg ();
			}
		}
		return new JsonView ( $data );
	}
}